package com.dhecp.project.statistics.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dhecp.common.annotation.Log;
import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.core.constant.ModuleTable;
import com.dhecp.core.utils.ExportExcelUtils;
import com.dhecp.project.common.controller.BaseModuleController;
import com.dhecp.project.statistics.domain.BankMoneyDetail;
import com.dhecp.project.statistics.service.BankMoneyDetailService;
import com.dhecp.project.system.domain.SysDictionaryForExport;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * 银行日记账 控制层
 * @author lwl
 * @version 2020年6月29日
 */
@Controller
@RequestMapping("/statistics/bankmoneydetail")
public class BankMoneyDetailController extends BaseModuleController{

private String moduleTable = ModuleTable.BANK_MONEY_DETAIL;
    
    @Autowired
    private BankMoneyDetailService bankMoneyDetailService;
    
    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;
    
    /**
     * 打开查询列表页
     * @param params
     * @return
     * @author DH-Xxj 
     */
	@RequiresPermissions("statistics:bankmoneydetail:view")
    @GetMapping()
    public ModelAndView listPage(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
    	params.put("entity", new BankMoneyDetail());
    	params.put("prefix","statistics/statistics"); //页面路径
    	
    	ModelAndView mv = this.openListPage(params);
    	mv.addObject("statistics", "bankmoneydetail");
		return mv;
    }
	
	/**
     * 查询所有信息
     * @param params
     * @return TableDataInfo
     * @author lwl
     */
	@GetMapping("/list")
    @RequiresPermissions("statistics:bankmoneydetail:list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params)
    {
		params.put("moduleTable", moduleTable);
        List<BankMoneyDetail> list = new ArrayList<BankMoneyDetail>();
        try {
        	list = bankMoneyDetailService.queryAll(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());            
        }
        return getDataTable(list);
    }
	
	/**
     * 数据导出Excel
     * @param params
     * @return
     * @throws Exception
     * @author DH-Xxj
     */
    @RequiresPermissions("statistics:bankmoneydetail:export")
    @Log(title = "银行日记账导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult export(@RequestParam Map<String, Object> params) throws Exception {
		params.put("moduleTable", moduleTable);
    	params.put("entity", new BankMoneyDetail()); 
        List<BankMoneyDetail> list = bankMoneyDetailService.queryAll(params);
        params.put("getFieldAttributesType", "export");
    	List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<BankMoneyDetail> util = new ExportExcelUtils<BankMoneyDetail>(moduleTable,new BankMoneyDetail());
        return util.exportExcel(list, fieldList, "银行日记账数据", "export");
    }
}
